package com.ngsky.ana.conf;

import java.io.*;
import java.util.Properties;

/**
 * @Author syx
 * @Desc
 * @Create 2020/6/16 13:42
 */
public class AppConstants {
    public final static int WINDOW_W = 1024;
    public final static int WINDOW_H = 900;

    public final static int MAX_IMG_SIZE = 20;

    public final static String DB_FILE = "03159cd7-1a3c-4ef9-8859-b00e090e09bf";

    public final static String DB_K_SAVEDIR = "savedir";


    public static String getDBPath() {
        String userHome = System.getProperties().getProperty("user.home");
        return userHome + "\\AppData\\Roaming\\ImageAna";
    }

    public static String getDBFile() {
        return getDBPath() + "\\" + "." + DB_FILE + ".properties";
    }

    /**
     * 存储全局配置数据
     */
    public static void insert(String key, String value) throws IOException {
        Properties pro = new Properties();
        pro.setProperty(key, value);
        pro.store(new FileOutputStream(new File(getDBFile())), "全局配置");
    }

    /**
     * 读取全局配置数据
     */
    public static String get(String key) {
        try {
            Properties pro = new Properties();
            pro.load(new FileReader(getDBFile()));
            return pro.getProperty(key);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
